home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / MotifScrollBarButton.java < prev    next >
Text File  |  1998-06-30  |  5KB  |  207 lines

  1. /*
  2.  * @(#)MotifScrollBarButton.java    1.9 98/02/02
  3.  * 
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  */
  20.  
  21. package com.sun.java.swing.plaf.motif;
  22.  
  23. import com.sun.java.swing.*;
  24. import com.sun.java.swing.event.*;
  25. import com.sun.java.swing.plaf.*;
  26.  
  27. import java.awt.*;
  28. import java.awt.event.*;
  29.  
  30. /**
  31.  * Motif scroll bar button.
  32.  * <p>
  33.  * Warning: serialized objects of this class will not be compatible with
  34.  * future swing releases.  The current serialization support is appropriate
  35.  * for short term storage or RMI between Swing1.0 applications.  It will
  36.  * not be possible to load serialized Swing1.0 objects with future releases
  37.  * of Swing.  The JDK1.2 release of Swing will be the compatibility
  38.  * baseline for the serialized form of Swing objects.
  39.  */
  40. public class MotifScrollBarButton extends JButton implements SwingConstants
  41. {
  42.     private int direction = NORTH;
  43.     private Color darkShadow = UIManager.getColor("controlShadow");
  44.     private Color lightShadow = UIManager.getColor("controlLtHighlight");
  45.  
  46.     public MotifScrollBarButton(int direction)
  47.     {
  48.     switch (direction) {
  49.     case NORTH:
  50.     case SOUTH:
  51.     case EAST:
  52.     case WEST:
  53.         this.direction = direction;
  54.         break;
  55.     default:
  56.         throw new IllegalArgumentException("invalid direction");
  57.     }
  58.  
  59.     setRequestFocusEnabled(false);
  60.     setOpaque(true);
  61.     setBackground(UIManager.getColor("ScrollBar.background"));
  62.     setForeground(UIManager.getColor("ScrollBar.foreground"));
  63.     }
  64.  
  65.  
  66.     public Dimension getPreferredSize() {
  67.     switch (direction) {
  68.     case NORTH: 
  69.     case SOUTH: 
  70.         return new Dimension(11, 12);
  71.     case EAST:
  72.     case WEST:
  73.     default:
  74.         return new Dimension(12, 11);
  75.     }
  76.     }
  77.  
  78.     public Dimension getMinimumSize() {
  79.     return getPreferredSize();
  80.     }
  81.  
  82.     public Dimension getMaximumSize() {
  83.     return getPreferredSize();
  84.     }
  85.  
  86.     public boolean isFocusTraversable() {
  87.     return false;
  88.     }
  89.  
  90.  
  91.     public void paint(Graphics g) 
  92.     {
  93.     int w = getWidth();
  94.     int h = getHeight();
  95.  
  96.     if (isOpaque()) {
  97.         g.setColor(getBackground());
  98.         g.fillRect(0, 0, w, h);
  99.     }
  100.  
  101.     boolean isPressed = getModel().isPressed();
  102.     Color lead = (isPressed) ? darkShadow : lightShadow;
  103.     Color trail = (isPressed) ? lightShadow : darkShadow;
  104.     Color fill = getForeground();
  105.  
  106.     int cx = w / 2;
  107.     int cy = h / 2;
  108.     int s = Math.min(w, h);
  109.  
  110.     switch (direction) {
  111.     case NORTH:
  112.         g.setColor(lead);
  113.         g.drawLine(cx, 0, cx, 0);
  114.         for (int x = cx - 1, y = 1, dx = 1; y <= s - 2; y += 2) {
  115.         g.setColor(lead);
  116.         g.drawLine(x, y, x, y);
  117.         if (y >= (s - 2)) {
  118.             g.drawLine(x, y + 1, x, y + 1);
  119.         }
  120.         g.setColor(fill);
  121.         g.drawLine(x + 1, y, x + dx, y);
  122.         if (y < (s - 2)) {
  123.             g.drawLine(x, y + 1, x + dx + 1, y + 1);
  124.         }
  125.         g.setColor(trail);
  126.         g.drawLine(x + dx + 1, y, x + dx + 1, y);
  127.         if (y >= (s - 2)) {
  128.             g.drawLine(x + 1, y + 1, x + dx + 1, y + 1);
  129.         }
  130.         dx += 2;
  131.         x -= 1;
  132.         }
  133.         break;
  134.  
  135.     case SOUTH:
  136.         g.setColor(trail);
  137.         g.drawLine(cx, s, cx, s);
  138.         for (int x = cx - 1, y = s - 1, dx = 1; y >= 1; y -= 2) {
  139.         g.setColor(lead);
  140.         g.drawLine(x, y, x, y);
  141.         if (y <= 2) {
  142.             g.drawLine(x, y - 1, x + dx + 1, y - 1);
  143.         }
  144.         g.setColor(fill);
  145.         g.drawLine(x + 1, y, x + dx, y);
  146.         if (y > 2) {
  147.             g.drawLine(x, y - 1, x + dx + 1, y - 1);
  148.         }
  149.         g.setColor(trail);
  150.         g.drawLine(x + dx + 1, y, x + dx + 1, y);
  151.         
  152.         dx += 2;
  153.         x -= 1;
  154.         }
  155.         break;
  156.  
  157.     case EAST:
  158.         g.setColor(lead);
  159.         g.drawLine(s, cy, s, cy);
  160.         for (int y = cy - 1, x = s - 1, dy = 1; x >= 1; x -= 2) {
  161.         g.setColor(lead);
  162.         g.drawLine(x, y, x, y);
  163.         if (x <= 2) {
  164.             g.drawLine(x - 1, y, x - 1, y + dy + 1);
  165.         }
  166.         g.setColor(fill);
  167.         g.drawLine(x, y + 1, x, y + dy);
  168.         if (x > 2) {
  169.             g.drawLine(x - 1, y, x - 1, y + dy + 1);
  170.         }
  171.         g.setColor(trail);
  172.         g.drawLine(x, y + dy + 1, x, y + dy + 1);
  173.  
  174.         dy += 2;
  175.         y -= 1;
  176.         }
  177.         break;
  178.  
  179.     case WEST:
  180.         g.setColor(trail);
  181.         g.drawLine(0, cy, 0, cy);
  182.         for (int y = cy - 1, x = 1, dy = 1; x <= s - 2; x += 2) {
  183.         g.setColor(lead);
  184.         g.drawLine(x, y, x, y);
  185.         if (x >= (s - 2)) {
  186.             g.drawLine(x + 1, y, x + 1, y);
  187.         }
  188.         g.setColor(fill);
  189.         g.drawLine(x, y + 1, x, y + dy);
  190.         if (x < (s - 2)) {
  191.             g.drawLine(x + 1, y, x + 1, y + dy + 1);
  192.         }
  193.         g.setColor(trail);
  194.         g.drawLine(x, y + dy + 1, x, y + dy + 1);
  195.         if (x >= (s - 2)) {
  196.             g.drawLine(x + 1, y + 1, x + 1, y + dy + 1);
  197.         }
  198.         dy += 2;
  199.         y -= 1;
  200.         }
  201.         break;
  202.     }
  203.     }
  204. }
  205.  
  206.  
  207.